<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**

 * Description of test
 *
 * @author Administrator
 */
class test  extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
                    $this->load->service('/wms/inventory_on_order_service');
                    $this->load->model('/Common_model');
                    $this->test();
    }
    function test()
    {
                $id= '42802';
                echo $id;
        $a=$this->Common_model->resetStatus($id = '42802');
                var_dump($a);
                ;exit;
        exit;
        $id= '42802';
        //#配件
        $partsList = $this->Common_model->selectCustom('mt_product_parts', array('pid' =>$id));
                $productFirst = $this->Common_model->selectFirst('mt_product', array('id' => $id));
                        $orderFirst = $this->Common_model->selectFirst('mt_order', array('id' => $productFirst['oid']));
                //订单锁定WMS可用库存
//                $setOk = $this->inventory_on_order_service->set_onorder_parts_list_t($partsList,$orderFirst['merchant_num'],$productFirst['inWarranty']);
           $wms_lock_url=blang_url('wmsApi/Stock/lock');
           $user='tomrepair.es';
           $timestamp=  time();
           $pass='omstomrepaires20161214';
           $sign= md5($user . $timestamp.$pass);
           $data['user']=$user;
           $data['timestamp']=$timestamp;
           $data['sign']=$sign;
           $data['data']['parts_list']=$partsList;
           $data['data']['product_first']=$productFirst;
//           echo http_build_query($data);
            $result=CurlPost($wms_lock_url,$data);
            var_dump($result);
    }
    function curl_post($url, $data)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_TIMEOUT, '60');  //定义超时3秒钟
        // POST数据
        curl_setopt($ch, CURLOPT_POST, 1);
        // 把post的变量加上
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));    //所需传的数组用http_bulid_query()函数处理一下，就ok了
        //执行并获取url地址的内容
        $output = curl_exec($ch);
        $errorCode = curl_errno($ch);
        $err = curl_error($ch);
//        var_dump($err);
//        var_dump( $data); 
        //释放curl句柄
        curl_close($ch);
//        var_dump($output);
        return $output;
    }
  function http($url, $method, $postfields = NULL, $headers = array()) { 
    $this->http_info = array(); 
    $ci = curl_init(); 
    /* Curl settings */
    curl_setopt($ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);//让cURL自己判断使用哪个版本 
    curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);//在HTTP请求中包含一个"User-Agent: "头的字符串。 
    curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);//在发起连接前等待的时间，如果设置为0，则无限等待 
    curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);//设置cURL允许执行的最长秒数 
    curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);//返回原生的（Raw）输出 
    curl_setopt($ci, CURLOPT_ENCODING, "");//HTTP请求头中"Accept-Encoding: "的值。支持的编码有"identity"，"deflate"和"gzip"。如果为空字符串""，请求头会发送所有支持的编码类型。 
    curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);//禁用后cURL将终止从服务端进行验证 
    curl_setopt($ci, CURLOPT_HEADERFUNCTION, array($this, 'getHeader'));//第一个是cURL的资源句柄，第二个是输出的header数据 
    curl_setopt($ci, CURLOPT_HEADER, FALSE);//启用时会将头文件的信息作为数据流输出 
    switch ($method) { 
      case 'POST': 
        curl_setopt($ci, CURLOPT_POST, TRUE); 
        if (!empty($postfields)) { 
          curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields); 
          $this->postdata = $postfields; 
        } 
        break; 
      case 'DELETE': 
        curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE'); 
        if (!empty($postfields)) { 
          $url = "{$url}?{$postfields}"; 
        } 
    } 
    if ( isset($this->access_token) && $this->access_token ) 
      $headers[] = "Authorization: OAuth2 ".$this->access_token; 
    $headers[] = "API-RemoteIP: " . $_SERVER['REMOTE_ADDR']; 
    curl_setopt($ci, CURLOPT_URL, $url ); 
    curl_setopt($ci, CURLOPT_HTTPHEADER, $headers ); 
    curl_setopt($ci, CURLINFO_HEADER_OUT, TRUE ); 
    $response = curl_exec($ci); 
    $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE); 
    $this->http_info = array_merge($this->http_info, curl_getinfo($ci)); 
    $this->url = $url; 
    if ($this->debug) { 
      echo "=====post data======\r\n"; 
      var_dump($postfields); 
  
      echo '=====info====='."\r\n"; 
      print_r( curl_getinfo($ci) ); 
  
      echo '=====$response====='."\r\n"; 
      print_r( $response ); 
    } 
    curl_close ($ci); 
    return $response; 
  }
}
class test_trans extends CI_Controller
{

    public function __construct()
    {
        parent::__construct();
         var_dump($this->db->trans_enabled);
        $this->db->trans_begin();
        $query = $this->db->query("UPDATE `wms_zcsq_order` SET `status`='1' WHERE (`order_id`='UN0000045')");
        var_dump($this->db->trans_enabled);$this->test();exit;
        $query = $this->db->query("UPDATE `wms_zcsq_order` SET `status`='1' WHERE (`order_id`='UN000004655')");
//        if ($this->db->trans_status() === FALSE)
//        {
            $this->db->trans_rollback();
//            return false;
//        }
//        else
//        {
//            $this->db->trans_commit();
//            return true;
//        }
    }
    function test()
    {
            $this->db->trans_rollback();
                        echo '555';
            return false;
    }

}

?>
